home *** CD-ROM | disk | FTP | other *** search
/ Trusted Irix /B 4.0.4 / Trusted-Irix B-4.0.1.iso / dist / eoe1.idb / bin / basename.z / basename
Text File  |  1992-04-03  |  963b  |  26 lines

  1. #! /bin/sh
  2. #    Copyright (c) 1984 AT&T
  3. #      All Rights Reserved
  4.  
  5. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  6. #    The copyright notice above does not evidence any
  7. #    actual or intended publication of such source code.
  8.  
  9. #ident    "@(#)basename:basename.sh    1.7"
  10. #ident    "$Header: /src_trees/calypso/att/usr/src/cmd/basename/RCS/basename.sh,v 1.4 86/12/08 18:00:34 bruce Exp $"
  11. if [ $# -gt 2 ]
  12. then
  13.     echo >&2 "Usage:  basename [ path [ suffix-pattern ] ]"
  14.     exit 1
  15. fi
  16. #    If no first argument or first argument is null, make first argument
  17. #    "."  Add beginning slash, then remove trailing slashes, then remove 
  18. #    everything up through last slash, then remove suffix pattern if 
  19. #    second argument is present.
  20. #    If nothing is left, first argument must be of form //*, in which
  21. #     case the basename is /.
  22. exec /bin/expr \
  23.     "/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' : "\\(.*\\)$2\$"  \|  \
  24.     "/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)'    \|  \
  25.     "/${1:-.}" : '.*/\(..*\)' 
  26.